/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session.TX;

import entity.establishment.OutletFood;
import entity.establishment.StakeholderFood;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Chen Zhe
 */
@Stateless
public class UpdateDataModelsSB implements UpdateDataModelsSBRemote {

    @PersistenceContext
    EntityManager em;
    
    @EJB
    private TCubeDataModelSBRemote tcubeDMSB;
    @EJB
    private StakeholderDataModelSBRemote stakeholderDMSB;
    @EJB
    private OutletDataModelSBRemote outletDMSB;
    
    @Override
    public void doMonthlyAnalytics() {
        //Insert method call to do the analytics here
//        Query q1 = em.createQuery("SELECT c FROM TCubeDataModel c");
//        List<TCubeDataModel> tdms = q1.getResultLiTst();
//        TCubeDataModel tdm = tdms.get(0);
//        tcubeDMSB = new TCubeDataModelSB();
//        stakeholderDMSB=new StakeholderDataModelSB();
//        outletDMSB = new OutletDataModelSB();
        
        tcubeDMSB.updateDataModel();

        Query q1 = em.createQuery("SELECT c FROM StakeholderFood c");
        List<StakeholderFood> sfs = q1.getResultList();
        for (StakeholderFood sf : sfs) {
            stakeholderDMSB.updateDataModel(sf.getName());
        }

        Query q2 = em.createQuery("SELECT c FROM OutletFood c");
        List<OutletFood> os = q2.getResultList();
        for (OutletFood o : os) {
            outletDMSB.updateDataModel(o.getId());
        }
    }
    
}
